<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>添加商场库</title>
		<link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
	    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
        <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
	    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
	    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
	    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
		<script type="text/javascript" src="/webapp/js/common/cities.js"></script>
	</head>
	<body>
		<div class="easyui-container-fluid">
            <div class="easyui-panel" style="border: none;">
                <div class="nav" id="nav"></div>
                <div class="easyui-panel" style="border:none;">
                	<form id="ff">
                        <div style="margin-bottom:20px;">
                            <label class="item-label" >*名称：</label>
                            <input type="text" class="easyui-textbox" name="name" style="width:174px;" prompt="请输入商场名称" data-options="required:true"/>
                        </div>
                		<div style="margin-bottom:20px;">
                			<label class="item-label">*类型：</label>
                			<select class="easyui-combobox" id="mallType" data-options="panelHeight:'auto'" required="required" style="width:174px;" name="type" prompt="--请选择类型--">
                				<option value=""></option>
                				<option value="SUPERMARKET">超市</option>
                                <option value="DEPARTMENT_STORE">百货</option>
                				<option value="PRO_SHOP">家电专营</option>
                                <option value="KA">全国家电连锁</option>
								<option value="BUILDING_MATERIAL">建材</option>
                			</select>
                		</div>
                		<div style="margin-bottom:20px;">
                			<label  class="item-label">*渠道：</label>
                			<select class="easyui-combobox" id="channel"  required="required" style="width:174px;" name="channelCode">
                			</select>
                		</div>
                        <div style="margin-bottom:20px;">
                            <label  class="item-label">*所在市：</label>
                            <select id="city" class="easyui-combobox"  required="required" style="width:174px;" name="cityCode">
                            </select>
                        </div>
		                <div style="margin-bottom:20px;">
                            <label class="item-label" >门店编码：</label>
                            <input type="text" class="easyui-textbox" style="width:174px;" name="customCode"/>
                        </div>
		                <div style="margin-bottom:20px;">
                            <label class="item-label" >门店数：</label>
                            <input type="text" class="easyui-textbox" style="width:174px;" name="shopCount"/>
                        </div>
						<div>
							<label class="item-label"><span class="item-required"></span>包含商场：</label>
							<input name="countent" class="easyui-tagbox countent" style="width:30%;min-height:100px;" data-options="multiline:true"/>
						</div>
                		<div style="margin-bottom:20px;">
                			<label class="item-label">备注：</label>
                			<input type="text" class="easyui-textbox" multiline="true" data-options="" style="width:30%;height:120px;" name="remark"/>
                		</div>
                        <div style="margin-bottom:20px;margin-left:100px;">
                            <a href="javascript:void(0);" class="easyui-linkbutton c8" style="width:80px" onclick="submitForm()">保存</a>
                            <a href="javascript:void(0);" class="easyui-linkbutton" style="width:80px;" onclick="clearForm()">取消</a>
                        </div>
                	</form>
                </div>
            </div>
		</div>
	</body>
    <script type="text/javascript">
        var id = getQueryParameter("id");
        $(function(){
            setNav();
            // initBelongingCityCombobox("belongingCity");
            initChannelSelect("channel")
			$.when(initCityCombobox("city")).done(function () {
				if(id) {
					$.ajax({
						url: config.url + "/mall/" + id,
						type: 'get',
						xhrFields: {withCredentials: true},
						dataType: "json",
						success: function (data) {
							//填充表单
							if (data) {
								$("#ff").form("load", changeProperty2String(data));
							}
						},
						error: function () {

						}
					});
				}
			});

            $("#province").combobox({
                onChange:function(newValue,oldValue){
                    console.log(newValue);
                    $("#city").combobox({
                        url:config.url+'/dictionary/getCityByProvince/'+newValue,
                        type:'get',
                        data:{id:id},
                        xhrFields:{withCredentials:true},
                    });
                }
            });
            if("online"==window.parent.workMode){
                $("#mallType").combobox({
                    data:[
                        {text:"专业电商",value:"SPECIALTY_EB",selected:true},
                        {text:"平台电商",value:"PLATFORM_EB"}
                    ]
                });
            }
        });
        function submitForm(){
            $("#ff").form("submit",{
               onSubmit:function(){
                  var valid = $(this).form('enableValidation').form('validate');
                  if(valid){
                      var mall = getFormData(document.getElementById("ff"));
                      var method = "POST";
                        if(id){
                          method = "PATCH";
                          mall.id = id;
                        }
                      var bm = $(".countent").combobox('getValues');
                      mall.countent=bm;
                      console.log(mall.countent);
                      $.ajax({
                         url:config.url+"/mall",
                         type:method,
                         data:JSON.stringify(mall),
                         dataType:'json',
                         contentType:'application/json;charset=UTF-8',
                         beforeSend:function(){
                            $.messager.progress({
                                title:"请稍等",
                                interval:50,
                                text:"操作进行中..."
							});
                         },
                         complete:function(){
                            $.messager.progress("close");
                         },
                         xhrFields:{withCredentials:true},
                          success:function(data){
							  if(data.returnMessage == "YES"){
								  $.messager.alert("提示","操作成功","info",function(){
									 window.parent.closeCurrentTab(true);
								  });
							  }else if(data.returnMessage == "NO"){
                                  $.messager.alert("提示","操作失败,该商场名已存在","error");
							  }
                          },
                          error:function(XMLHttpRequest,textStatus,thrown){
                              $.messager.alert("提示","操作失败","error");
                          }
                      });
                       return false;
                    }
                    return false;
                  
               }
          });
        }
        function clearForm(){
            window.parent.closeCurrentTab();
        }
    </script>
</html>